/* eslint-disable @typescript-eslint/no-explicit-any */
import { defineStore } from "pinia"
// import { ref } from "vue"
import { getFriendsUidList } from '@/api/friends'

export const useChatStore = defineStore('chat-store', {
    state: () => ({
        friendsList: null,
        chatMap: new Map(),
    }),
    getters: {
        // doubleCount: (state) => state.count * 2,
        getFriendsList: (state) => {
            return state.friendsList
        },
        getChatMapKeys: (state) => {
            return Array.from(state.chatMap.keys())
        }
    },
    actions: {
        async fetchFriendsList() {
            const res = await getFriendsUidList()
            if (res.data.code === 0 && res.data.data) {
                this.friendsList = res.data.data.friends
            }
            return this.friendsList
        },
        logout() {
            this.chatMap = new Map()
            this.friendsList = null
        }

    },
})